//
//  baoxiuxiangqingViewController.m
//  wuyeviewcon
//
//  Created by dsdf on 16/1/26.
//  Copyright © 2016年 joey. All rights reserved.
//

#import "baoxiuxiangqingViewController.h"
#import "ToolTipView.h"
#import "DetailsTableViewCell.h"

@interface baoxiuxiangqingViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    BOOL isFlag;
    UITableView * _tableView;
    
    UIImageView * imgView;
    UIButton * detailedBtn;
    
    UILabel * detailsLabel;
    UIImageView * deImage0,*deImage1,*deImage2,*deImage3;
    UIImageView * btnImag;
    UIView * linView;
    UIImageView * img;
}



@end

@implementation baoxiuxiangqingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationController.navigationBar.barTintColor = [[UIColor alloc] initWithRed:230/255.0 green:55/255.0 blue:55/255.0 alpha:1.0];
    
    
    self.title = @"详情";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 20, 20);
    [button setBackgroundImage:[UIImage imageNamed:@"return@2x.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    
    UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(0, 0,25, 13);
    [button1 setBackgroundImage:[UIImage imageNamed:@"Messages-副本@2x.png"] forState:UIControlStateNormal];
    [button1 setTitle:@"取消" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(youcequxiao) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *  rightItem= [[UIBarButtonItem alloc] initWithCustomView:button1];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    
    
    
    
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 55, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-_underpartView.frame.origin.y-55) style:UITableViewStylePlain];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_underpartView addSubview:_tableView];
    
    
    imgView = [[UIImageView alloc] initWithFrame:CGRectMake(11, 0, [UIScreen mainScreen].bounds.size.width-22, 45)];
    imgView.image = [UIImage imageNamed:@"文本可拉伸区域.png"];
    [_detailsView addSubview:imgView];
    
    
    btnImag = [[UIImageView alloc] initWithFrame:CGRectMake(45+([UIScreen mainScreen].bounds.size.width-50-20-100)/2, 14, 100, 20)];
    btnImag.image = [UIImage imageNamed:@"详情边框.png"];
    [_detailsView addSubview:btnImag];
    
    img = [[UIImageView alloc] initWithFrame:CGRectMake(98+([UIScreen mainScreen].bounds.size.width-50-20-100)/2, 14, 20, 20)];
    img.image = [UIImage imageNamed:@"箭头向下.png"];
    [_detailsView addSubview:img];
    
    detailedBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    detailedBtn.frame = btnImag.frame;
    [detailedBtn setTintColor:[UIColor redColor]];
    [detailedBtn setTitle:@"详情    " forState:UIControlStateNormal];
    detailedBtn.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [detailedBtn addTarget:self action:@selector(detailsBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_detailsView addSubview:detailedBtn];
    
    
    
    
    linView = [[UIView alloc] initWithFrame:CGRectMake(45, 14, [UIScreen mainScreen].bounds.size.width-50-20, 1)];
    linView.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [_detailsView addSubview:linView];
    
    
    detailsLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, [UIScreen mainScreen].bounds.size.width-50-20, 47)];
    detailsLabel.font = [UIFont systemFontOfSize:13.0];
    detailsLabel.numberOfLines = 0;
    detailsLabel.text = @"卫生间及厨房水管、水龙头、马桶、手盆、洗菜盆、 热水器硬链接，铝塑管更换成热熔管，暗管改明管。";
    detailsLabel.alpha = 0;
    
    deImage0 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 55, 60, 60)];
    //deImage0.backgroundColor = [UIColor redColor];
    deImage0.image=[UIImage imageNamed:@"xiangqing图层-1@2x.png"];
    deImage0.alpha = 0;
    
    deImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(110+([UIScreen mainScreen].bounds.size.width-310)/4, 55, 60, 60)];
    deImage1.image=[UIImage imageNamed:@"xiangqing图层-2@2x.png"];
    //deImage1.backgroundColor = [UIColor yellowColor];
    deImage1.alpha = 0;;
    
    deImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(170+([UIScreen mainScreen].bounds.size.width-310)/4*2, 55, 60, 60)];
    deImage2.image=[UIImage imageNamed:@"xiangqing图层-3@2x.png"];
   // deImage2.backgroundColor = [UIColor cyanColor];
    deImage2.alpha = 0;
    
    deImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(230+([UIScreen mainScreen].bounds.size.width-310)/4*3, 55, 60, 60)];
    deImage3.image=[UIImage imageNamed:@"xiangqing图层-4@2x.png"];
    //deImage3.backgroundColor = [UIColor orangeColor];
    deImage3.alpha = 0;
    
    [_detailsView addSubview:detailsLabel];
    [_detailsView addSubview:deImage0];
    [_detailsView addSubview:deImage1];
    [_detailsView addSubview:deImage2];
    [_detailsView addSubview:deImage3];

    
    
}

//导航取消按钮
- (void)youcequxiao {
    ToolTipView * toolView = [[ToolTipView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    UIWindow* window = [UIApplication sharedApplication].delegate.window;
    [window addSubview:toolView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)fanhui {
    
    [self.navigationController popViewControllerAnimated:YES];
    //[self dismissModalViewControllerAnimated:YES];
}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        static NSString * str = @"cell1";
        DetailsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"DetailsTableViewCell" owner:nil options:nil]objectAtIndex:1];
            cell.backgroundColor = [UIColor clearColor];
        }
        return cell;
    }else {
        static NSString * str = @"cell";
        DetailsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"DetailsTableViewCell" owner:nil options:nil]objectAtIndex:0];
            cell.backgroundColor = [UIColor clearColor];
        }
        if (indexPath.row == 0) {
            cell.imag.image = [UIImage imageNamed:@"维修图标.png"];
            cell.contentLabel.textColor = [UIColor redColor];
            cell.topView.alpha = 0;
        }else {
            cell.imag.image = [UIImage imageNamed:@"图标背景.png"];
            if (indexPath.row == 3) {
                cell.tilView.alpha = 0;
            }
        }
        return cell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 163;
    }else {
        return 80;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}


//详情按钮
- (IBAction)detailsBtnClick:(id)sender {
    isFlag = !isFlag;
    if (isFlag) {
        
        
        imgView.frame = CGRectMake(imgView.frame.origin.x, imgView.frame.origin.y, imgView.frame.size.width, 155);
        _detailsView.frame = CGRectMake(_detailsView.frame.origin.x, _detailsView.frame.origin.y, _detailsView.frame.size.width, _detailsView.frame.size.height+110);
        
        _underpartView.frame = CGRectMake(_underpartView.frame.origin.x, 300+110, _underpartView.frame.size.width, _underpartView.frame.size.height-110);
        _tableView.frame = CGRectMake(_tableView.frame.origin.x, _tableView.frame.origin.y, _tableView.frame.size.width, _tableView.frame.size.height-110);
        
        
        detailsLabel.alpha = 1;
        deImage0.alpha = 1;
        deImage1.alpha = 1;
        deImage2.alpha = 1;
        deImage3.alpha = 1;
        
        //        btnImag.frame = CGRectMake(137, 123, 100, 20);
        btnImag.frame = CGRectMake(45+([UIScreen mainScreen].bounds.size.width-50-20-100)/2, 123, 100, 20);
        [detailedBtn setTitle:@"收起    " forState:UIControlStateNormal];
        detailedBtn.frame = btnImag.frame;
        linView.frame = CGRectMake(45, 123, [UIScreen mainScreen].bounds.size.width-50-20, 1);
        img.frame = CGRectMake(98+([UIScreen mainScreen].bounds.size.width-50-20-100)/2, 123, 20, 20);
        img.image = [UIImage imageNamed:@"箭头向上.png"];
        
    }else{
        _detailsView.frame = CGRectMake(_detailsView.frame.origin.x, _detailsView.frame.origin.y, _detailsView.frame.size.width, _detailsView.frame.size.height+110);
        _underpartView.frame = CGRectMake(_underpartView.frame.origin.x, _underpartView.frame.origin.y-154, _underpartView.frame.size.width, _underpartView.frame.size.height+110);
        _tableView.frame = CGRectMake(_tableView.frame.origin.x, _tableView.frame.origin.y, _tableView.frame.size.width, _tableView.frame.size.height+110);
        imgView.frame = CGRectMake(imgView.frame.origin.x, imgView.frame.origin.y, imgView.frame.size.width, imgView.frame.size.height-110);
        
        //        btnImag.frame = CGRectMake(137, 14, 100, 20);
        btnImag.frame = CGRectMake(45+([UIScreen mainScreen].bounds.size.width-50-20-100)/2, 14, 100, 20);
        [detailedBtn setTitle:@"详情    " forState:UIControlStateNormal];
        detailedBtn.frame = btnImag.frame;
        linView.frame = CGRectMake(45, 14, [UIScreen mainScreen].bounds.size.width-50-20, 1);
        
        img.frame = CGRectMake(98+([UIScreen mainScreen].bounds.size.width-50-20-100)/2, 14, 20, 20);
        img.image = [UIImage imageNamed:@"箭头向下.png"];
        
        detailsLabel.alpha = 0;
        deImage0.alpha = 0;
        deImage1.alpha = 0;
        deImage2.alpha = 0;
        deImage3.alpha = 0;
    }
    
}


@end
